<template>
  <div class="task-view">
    <div class="header">
      <div class="header-content-box">
        <div class="header-left">
          <div class="title"><span @click="backToProjectDetail">{{ curTaskInfo.taskName }}</span></div>
        </div>
        <div class="header-right">
          <div class="action">
            <span><i class="circle-status" />{{ curTaskInfo.taskStatus }}</span>
          </div>
        </div>
      </div>
      <ul class="nav-list">
        <li class="main-nav-list nav-left clearfix">
          <ul class="main-nav-list-container">
            <li :class="{'active': activeTab === 0}" class="nav-item link-item" @click="toggleActive(0)">结果</li>
            <li :class="{'active': activeTab === 1}" class="nav-item link-item" @click="toggleActive(1)">图表</li>
            <li :class="{'active': activeTab === 2}" class="nav-item link-item" @click="toggleActive(2)">配置</li>
          </ul>
        </li>
      </ul>
    </div>
    <div class="content">
      <router-view />
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  data() {
    return {
      activeTab: 0,
      // Tabs切换路由对照，数组顺序不可变化
      tabsRoutePath: [
        '/task/detail/result',
        '/task/detail/chart',
        '/task/detail/config'
      ]
    }
  },
  computed: {
    ...mapGetters([
      'curTaskInfo'
    ])
  },
  watch: {
    '$route'(to, from) {
      this.tabsRoutePath.forEach((el, i) => {
        if (el === to.fullPath) {
          this.activeTab = i
        }
      })
    }
  },
  mounted() {
    // 根据路由计算当前激活Tab
    this.tabsRoutePath.forEach((v, index) => {
      if (v === this.$router.currentRoute.fullPath) {
        this.activeTab = index
      }
    })
  },
  methods: {
    // tab页切换
    toggleActive(val) {
      this.activeTab = val
      const path = this.tabsRoutePath[this.activeTab]
      this.$router.push({ 'path': path })
    },
    // 返回项目详情
    backToProjectDetail() {
      this.$router.push({ path: '/task/index' })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.task-view .header {
	height: 150px;
	background: #ffffff;
}

.task-view .header .header-content-box {
	display: flex;
	height: 70%;
	width: 100%;
	margin: 0 auto;
	max-width: 1000px;
	padding-top: 30px;
	box-sizing: border-box;
}

.task-view .header .header-content-box .header-left {
	width: 50%;
}

.task-view .header .header-content-box .header-left .title {
	font-family: PingFangSC-Medium;
	font-size: 18px;
	color: #3780f7;
	letter-spacing: 0;
}

.task-view .header .header-content-box .header-left .title span {
	cursor: pointer;
}

.task-view .header .header-content-box .header-left .desc {
	height: 80%;
	padding: 20px 0;
	font-family: PingFangSC-Regular;
	font-size: 14px;
	color: #666;
	letter-spacing: 0;
	line-height: 24px;
	box-sizing: border-box;
}

.task-view .header .header-content-box .header-right {
	width: 50%;
	display: flex;
	justify-content: flex-end;
}

.task-view .header .header-content-box .header-right .action {
	height: 20px;
	line-height: 20px;
}

.task-view .header .header-content-box .header-right .action span {
	color: #666;
	cursor: pointer;
	display: inline-flex;
}

.task-view .header .header-content-box .header-right .action span:hover {
	color: #4285f4;
}

.task-view .header .header-content-box .header-right .action span:first-child {
	margin-right: 12px;
}

.task-view .header .header-content-box .header-right .action .circle-status {
	padding: 4.5px;
	position: absolute;
	margin-top: 5px;
	margin-left: -15px;
	border-radius: 50%;
	background-image: linear-gradient(-180deg, #5daf34 0%, #5daf34 100%);
}

.task-view .header .nav-list {
	width: 100%;
	height: 30%;
	position: relative;
	margin: 0 auto;
	max-width: 1000px;
	display: flex;
  list-style: none;
  padding-inline-start: 0
}

.task-view .header .nav-list .main-nav-list {
	height: 100%;
}

.task-view .header .nav-list .main-nav-list .main-nav-list-container {
	display: flex;
	height: 100%;
	align-items: flex-end;
  padding-inline-start: 0
}

.task-view .header .nav-list .main-nav-list .main-nav-list-container li:first-child {
	margin-left: 0;
}

.task-view .header .nav-list .main-nav-list .main-nav-list-container .nav-item {
	padding: 0 10px;
	font-size: 14px;
	font-weight: bold;
	color: #2d323b;
	display: flex;
	justify-content: center;
	align-items: center;
	cursor: pointer;
	position: relative;
	margin: 0;
}

.task-view .header .nav-list .main-nav-list .main-nav-list-container .nav-item >a {
	color: #666;
	text-decoration: none;
	cursor: pointer;
}

.task-view .header .nav-list .main-nav-list .main-nav-list-container .nav-item >a:before {
	content: '';
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	left: 0;
}

.task-view .header .nav-list .main-nav-list .main-nav-list-container .link-item {
	padding: 0 20px;
	height: 50px;
	margin-left: 30px;
}

.task-view .header .nav-list .main-nav-list .nav-item.active {
	box-shadow: inset 0 -2px 0 #3780f7;
}

.task-view .header .nav-left {
	width: 70%;
}

.task-view .header .nav-right {
	width: 40%;
	display: flex;
	align-items: center;
	justify-content: flex-end;
}

.task-view .content {
		width: 100%;
    position: relative;
    margin: 0 auto;
    max-width: 1000px;
    padding: 20px 20px 80px;
    background: #fff;
    margin-top: 20px;
}
</style>
